package com.yand.frame.service.impl;


import com.yand.frame.dao.ActivityMenuMapper;
import com.yand.frame.dao.UserDao;
import com.yand.frame.entity.ActivityMenu;
import com.yand.frame.entity.ActivityUser;
import com.yand.frame.service.LoginService;
import com.yand.frame.utils.TreeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 登录相关服务
 */
@Service
public class LoginServiceImpl implements LoginService {



    @Autowired
    private UserDao userDao;

    @Autowired
    private ActivityMenuMapper activityMenuMapper;

    @Autowired
    private TreeUtil treeUtil;


    /**
     * 登录
     * 根据登录者的用户名获取当前的用户
     * @param name
     * @param
     */
    public ActivityUser getActivityUser(String name) {
        return userDao.getUser(name);
    }

    /**
     * 通过登录者的角色id获取所有的菜单id
     */
    public List<ActivityMenu> getMenuListByRoleId(Integer roleId){
        List<ActivityMenu> activityMenuList = activityMenuMapper.queryMenuList(roleId);
        /**
         * 递归查询所有的菜单按照，父子节点的关系，拼接成树
         */
        List<ActivityMenu> menuTreeList = (List<ActivityMenu>)treeUtil.getAllTreeJavaBean(activityMenuList);
        return menuTreeList;
    }

}
